<script type="text/javascript">

//    initTree();
//    function initTree()
//    {
//        changeZtree(2);
//    }
//    function changeZtree(t) {
//        var $panel = $.CurrentNavtab
//        var $t     = $('#ztree1'),
//                $span  = $('#ztree-'+ t),
//                $log   = $('#ztree-log'),
//                op     = $t.data()
//
//        if (t != 7)
//            $.fn.zTree.destroy('ztree1')
//
//        var add    = op.addHoverDom ? null : 'edit',
//                remove = op.removeHoverDom ? null : 'edit'
//
//        $t.data('addHoverDom', add).data('removeHoverDom', remove)
//
//        $log.val('data-add-hover-dom="'+ add +'"\r\n' + 'data-remove-hover-dom="'+ remove +'"')
//        $span.text(($span.text() == '无') ? '显示' : '无')
//        $panel.initui()
//    }
    //单击事件
    function ZtreeClick(event, treeId, treeNode) {
        event.preventDefault()

        var $detail = $('#ztree-detail')

        if (treeNode.name) $('#tree_node_name').val(treeNode.name)
        if (treeNode.pid) {
            $('#tree_node_pid').val(treeNode.pid)
        } else {
            var parentTId = treeNode.parentTId;
            var zTree  = $.fn.zTree.getZTreeObj("ztree1");
            var pid = zTree.getNodeByTId(treeNode.parentTId).id;
            if(pid)
            {
                $('#tree_node_pid').val(pid)
            }
            else {
                $('#tree_node_pid').val('')
            }
        }
        if (treeNode.id) {
            $('#tree_node_id').val(treeNode.id)
        } else {
            $('#tree_node_id').val('')
        }
        $detail.attr('tid', treeNode.tId)
        $detail.show()
    }

    //保存属性
    function M_Ts_Menu() {
        var zTree  = $.fn.zTree.getZTreeObj("ztree1")
        var name   = $('#tree_node_name').val()
        var id    = $('#tree_node_id').val()
        var pid  = $('#tree_node_pid').val()

        if ($.trim(name).length == 0) {
            alertMsg.error('名称不能为空！')
            return;
        }
//        var upNode = zTree.getSelectedNodes()[0]
//
//        if (!upNode) {
//            alertMsg.error('未选中任何菜单！')
//            return
//        }

        $.ajax({
            url: "/admin/templatetype/save"
            , type: "POST"
            , async:false
            , data: "id="+id+"&pid="+pid+"&typeName="+name
            , success: function( data, textStatus, jqXHR ){
                ajaxTree();
            }
        });

    }

    //删除前事件
    function M_BeforeRemove(treeId, treeNode) {
//        var $log = $('#ztree-log')
//        $log.val('准备删除：'+ treeNode.name +'！\n'+ $log.val())

//        alert(treeNode.id=='root');
        if(treeNode.id=='1')
        {
            $(this).alertmsg('error', '根节点不允许删除！')
            return false;
        }
        if(treeNode.children)
        {
            $(this).alertmsg('error', '该节点存在子节点，请先删除子节点，再删除该节点！');
            return false;
        }

        return true
    }
    //删除结束事件
    function M_NodeRemove(event, treeId, treeNode) {
//        var $log = $('#ztree-log')
//        $log.val('删除成功！\n'+ $log.val())
        $.ajax({
            url: "/admin/templatetype/delete"
            , type: "POST"
            , async:false
            , data: "ids="+treeNode.id
            , success: function( data, textStatus, jqXHR ){
                ajaxTree();
            }
        });
    }
    function ajaxTree() {

        $.ajax({
            url: "/admin/templatetype/ajaxtree"
            , type: "POST"
            , async:false
            , success: function( data, textStatus, jqXHR ){
                $('#treeDiv').html(data);
            }
        });
    }
    ajaxTree();

</script>
<div class="bjui-pageContent">
    <div style="padding:20px;">
        <div class="clearfix">
            <div id="treeDiv" style="float:left; width:320px; height:96%; overflow:auto;">


            </div>
            <div id="ztree-detail" style="display:none; margin-left:330px; width:200px; height:240px;">
                <div class="bs-example" data-content="详细信息">
                    <div class="form-group">
                        <label for="typeName" class="control-label x85">名称：</label>
                        <input type="text" class="form-control validate[required] required" name="m.name" id="tree_node_name" size="15" placeholder="名称" />
                        <input type="hidden" name="m.pid" id="tree_node_pid"  />
                        <input type="hidden" name="m.id" id="tree_node_id"  />
                    </div>

                    <div class="form-group" style="padding-top:8px; border-top:1px #DDD solid;">
                        <label class="control-label x85"></label>
                        <button class="btn btn-green" onclick="M_Ts_Menu();">更新</button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<#--<div class="bjui-pageFooter">-->
    <#--<ul>-->
        <#--<li><button type="button" class="btn-close" data-icon="close">关闭</button></li>-->
    <#--</ul>-->
<#--</div>-->